package com.hbnu.exercise.net;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServerDemo04
{
    public static void main(String[] args)
    {
        try
        {
            ServerSocket serverSocket = new ServerSocket(8888);

            Socket socket = serverSocket.accept();

            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter printWriter = new PrintWriter(new FileWriter("E:\\test.txt"), true);
            PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);

//            DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
//            long time = dataInputStream.readLong();

            String line = null;
            while ((line = in.readLine()) != null)
            {
//                if (line.equalsIgnoreCase(time + ""))
//                    break;
                printWriter.println(line);
            }

            out.println("文件上传成功");

            printWriter.close();
            serverSocket.close();
        } catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }
}
